package com.hhf.rrd.transformation;

import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.api.java.tuple.Tuple2;

import java.util.ArrayList;
import java.util.List;

/**
 * top n
 *
 * @author huanghaifeng15
 * @date 2022/2/11 12:41
 **/
public class TopnApp {
    public static void main(String[] args) throws Exception {
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

        List<Tuple2<Integer,String>> list = new ArrayList<>();

        list.add(Tuple2.of(1, "Hadoop"));
        list.add(Tuple2.of(1, "Spark"));
        list.add(Tuple2.of(1, "Flink"));
        list.add(Tuple2.of(1, "Hadoop"));
        list.add(Tuple2.of(2, "Java"));
        list.add(Tuple2.of(2, "Spring"));
        list.add(Tuple2.of(2, "Linux"));
        list.add(Tuple2.of(2, "Vue"));

        DataSource<Tuple2<Integer, String>> dataSource = env.fromCollection(list);
        dataSource.groupBy(0).first(1
                )
                .print();
    }
}
